# multivariate one step problem
from numpy import array
from numpy import hstack
from pandas import read_csv,datetime
from keras.preprocessing.sequence import TimeseriesGenerator

def parse(x):
    return datetime.strptime(x, '%Y %m')

# define dataset
dataset = read_csv(
    'E:\lyf_ML_Drought\coding\ML_Drought_Prediction\indices_caculate\\result\multi_spei_csv\SPEI-12\Multi_SPEI-12_52533.txt',
    header=0, parse_dates=[['year', 'month']], index_col=0, date_parser=parse)
dataset.index.name = 'time'
dataset.drop(columns=['average_air_pressure'], inplace=True)

in_seq1 = array(dataset)
in_seq2 = array(dataset['SPEI'])

# # reshape series
# in_seq1 = in_seq1.reshape((len(in_seq1), 1))
# in_seq2 = in_seq2.reshape((len(in_seq2), 1))

# print('seq1',in_seq1)
# print('seq2',in_seq2)
#
# # horizontally stack columns
# dataset = hstack((in_seq1, in_seq2))
# print(dataset)
#
# define generator
n_input = 1
generator = TimeseriesGenerator(in_seq1, in_seq2, length=n_input, batch_size=1)
# number of samples
print('Samples: %d' % len(generator))
#
# print each sample
for i in range(len(generator)):
    x, y = generator[i]
    print('%s => %s' % (x, y))